/**
 * Created on Sun Feb 27 11:37:43 CST 2011
 * Copyright SinoBest, 2010-2011, All rights reserved.
 */package cn.com.test.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.test.dao.Banuser;


/**
 * @Author zhou
 * @Date Sun Feb 27 11:37:43 CST 2011
 * @to-do 
 */public class BanuserDAO extends HibernateDaoSupport {
	
	private static final Log log = LogFactory.getLog(BanuserDAO.class);
	
	// property constants
	public static final String BANID = "banid";
	public static final String USERNAME = "username";
	public static final String GAME = "game";
	public static final String AREA = "area";
	public static final String NICKNAME = "nickname";
	public static final String REATION = "reation";
	public static final String DUETIME = "duetime";
	public static final String CREATORID = "creatorid";
	public static final String CREATETIME = "createtime";
	
	// property constants
	protected void initDao() {
		// do nothing
	}
	
	public void save(Banuser transientInstance) {
		log.debug("saving Banuser instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void delete(Banuser persistentInstance) {
		log.debug("deleting Banuser instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public Banuser findById(java.lang.String id) {
		log.debug("getting Banuser instance with id: " + id);
		try {
			Banuser instance = (Banuser) getHibernateTemplate().get(
					"cn.com.test.dao.Banuser", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public List findAll() {
		log.debug("finding all Banuser instances");
		try {
			String queryString = "from Banuser";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public Banuser merge(Banuser detachedInstance) {
		log.debug("merging Banuser instance");
		try {
			Banuser result = (Banuser) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
	
	public void attachDirty(Banuser instance) {
		log.debug("attaching dirty Banuser instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Banuser instance) {
		log.debug("attaching clean Banuser instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static BanuserDAO getFromApplicationContext(ApplicationContext ctx) {
		return (BanuserDAO) ctx.getBean("BanuserDAO");
	}
	
	public List findByExample(Banuser instance) {
		log.debug("finding Banuser instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
	
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Banuser instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Banuser as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findByBanid(Object banid) {
		return findByProperty(BANID, banid);
	}
	public List findByUsername(Object username) {
		return findByProperty(USERNAME, username);
	}
	public List findByGame(Object game) {
		return findByProperty(GAME, game);
	}
	public List findByArea(Object area) {
		return findByProperty(AREA, area);
	}
	public List findByNickname(Object nickname) {
		return findByProperty(NICKNAME, nickname);
	}
	public List findByReation(Object reation) {
		return findByProperty(REATION, reation);
	}
	public List findByDuetime(Object duetime) {
		return findByProperty(DUETIME, duetime);
	}
	public List findByCreatorid(Object creatorid) {
		return findByProperty(CREATORID, creatorid);
	}
	public List findByCreatetime(Object createtime) {
		return findByProperty(CREATETIME, createtime);
	}

}